﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

using LowLevelGraphics.ColorSpaces;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// 
    /// </summary>
    public class Farbton2 : BaseImageFilter, ITwoSourceFilter
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Farbton"/> class.
        /// </summary>
        public Farbton2()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Farbton"/> class.
        /// </summary>
        /// <param name="_farbton">The _farbton.</param>
        internal Farbton2(Farbton2 _farbton)
        {
        }

        /// <summary>
        /// Execute this Filter
        /// A Debug Statement is written if a concrete Filter is called
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            Process((UnsafeBitmap)_bitmap.Clone(), _bitmap);
            return _bitmap;
        }

        #region ITwoSourceFilter Members

        /// <summary>
        /// Processes the specified _bitmap source.
        /// </summary>
        /// <param name="_bitmapSource">The _bitmap source.</param>
        /// <param name="_bitmapDest">The _bitmap dest.</param>
        /// <returns></returns>
        public UnsafeBitmap Process(UnsafeBitmap _bitmapSource, UnsafeBitmap _bitmapDest)
        {
            UnsafeBitmap bitmapSource = _bitmapSource;
            UnsafeBitmap bitmapDest = _bitmapDest;

            Color color = Color.Transparent;

            int nWidth = bitmapSource.Width;
            int nHeight = bitmapSource.Height;

            int y = 0;
            int x = 0;
            for (y = 0; y < nHeight; y++)
            {
                for (x = 0; x < nWidth; x++)
                {
                    color = bitmapSource.GetPixel(x, y);

                    HSV hsv1 = new HSV(color);
                    HSV hsv2 = new HSV(color);

                    HSV hsvResult = new HSV(color);
                    color = hsv1.ToColor();
                    bitmapDest.SetPixel(x, y, color);
                }
            }
            bitmapSource.Dispose();
            bitmapDest.Dispose();

            return _bitmapDest;
        }

        #endregion
        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new Farbton2(this);
        }
    }
}
